<template>
  <div v-if="list.length">
    <p class="act-title">超值福利加购</p>
    <el-checkbox-group v-model="addActValue"
      class="act-checkbox-group"
      @change="onAddActChange">
      <el-checkbox v-for="item in list" :label="item.id" :key="item.id" class="act-checkbox">
        <span class="act-label">{{ item.act_name }}</span>
        <p>
          <span class="act_price">￥{{ item.setting.price | moneyToyuan }}</span>
          <span class="act-origin_price" v-if="item.setting.origin_price">￥{{ item.setting.origin_price | moneyToyuan }}</span>
        </p>
      </el-checkbox>
    </el-checkbox-group>
  </div>
</template>
<script>
export default {
  name: 'AddActList',
  props: {
    list: Array,
    value: Array
  },
  model: {
    prop: 'value',
    event: 'input'
  },
  data () {
    return {
      // addActValue: []
    }
  },
  computed: {
    isAddActCheckbox () {
      return this.list.some(it => it.setting['show-type'] === 2)
    },
    addActValue: {
      get () {
        return this.value
      },
      set (val) {
        this.$emit('input', val)
      }
    }
  },
  methods: {
    onAddActChange (val) {
      if (this.isAddActCheckbox) return
      const item = val.at(-1)
      if (item) {
        this.addActValue = [item]
      }
    }
  }
}
</script>
<style lang="scss">
.act-title{
  margin-top: 10px;
  color: #fff;
  font-size: 12px;
  font-weight: bold;
  &::before{
    content: ' ';
    display: inline-block;
    width: 4px;
    height: 12px;
    margin-right: 8px;
    vertical-align: -0.05em;
    background: #FFCE5A;
    border-radius: 29px
  }
}
.act-checkbox-group{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}
.act-checkbox{
  display: flex;
  align-items: center;
  padding: 5px 15px 5px 18px;
  min-height: 36px;
  background: rgba(255,255,255,0.05);
  border-radius: 6px;
  margin: 0;
  overflow: hidden;
  &:hover{
    background-color: rgba(255, 255, 255, 0.1);
    .el-checkbox__inner{
      border-color: #2FC670!important;
      // background-color: #2FC670!important;
    }
  }
  &.is-checked{
    background: #FEE7D3;
    .el-checkbox__inner{
      border-color: #2FC670!important;
      background-color: #2FC670!important;
      &::after{
        border-color: #fff;
      }
    }
    .el-checkbox__label{
      color: #7B4801;
    }
  }
  &.is-disabled{
    opacity: .6;
    .el-checkbox__inner{
      opacity: .3;
    }
  }
  .el-checkbox__inner{
    display: block;
    border-radius: 2px;
    border-color: #898989;
    background-color: #5A5A5A;
  }
  .el-checkbox__label{
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-left: 12px;
    overflow: hidden;
    color: #fff;
    font-size: 12px;
  }
  .act-label{
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .pkg-icon{
    font-size: 18px;
    margin-right: 4px;
  }
  .pkg-title{
    flex: 1;
    white-space: normal;
  }
  .pkg-info{
    padding-left: 4px;
  }
}
.act-origin_price{
  margin-left: 4px;
  opacity: 0.5;
  text-decoration: line-through;
}
</style>
